<?php

namespace app\api\model\order;

use app\logic\model\order\OrderMusicLogicModel;
use app\logic\single\GoodsSingle;

class OrderMusicApiModel extends OrderMusicLogicModel
{

    public function getFindByUserIdAndId(int $id = 0, int $user_id = 0,array $where=[])
    {
        if(empty($id) || empty($user_id)){
            return false;
        }
        return $this->where('id',$id)
            ->where('buyer_id',$user_id)
            ->where($where)
            ->find();
    }

    public function getApiList($param=[], $where=[], $field='*', $page=1, $limit=15,$order='id desc')
    {
        $query = $this->where($where)->where(function ($q) use ($param){
            if(check_request($param,'user_id')){
                $q->where('buyer_id',$param['user_id']);
            }if(check_request($param,'status')){
                $q->where('status',$param['status']);
            }
        })->hidden(['delete_time']);
        $list = $query->field($field)->page($page,$limit)->order($order)->select()->toArray();
        $count = $query->count();
        if($count >=1){
            foreach ($list as &$val){
                $val['detail'] = OrderMusicDetailApiModel::getByOrderId($val['id']);
            }
            unset($val);
        }
        return [$list,$count];
    }
}